﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Diagnostics;

namespace TP_MVVM.DataAccess
{
    public class Person
    {
        /// <summary>
        /// charge la liste des personnes contenue dans un fichier XML
        /// </summary>
        /// <returns>une liste de personne</returns>
        public List<Model.Person> Load()
        {
            try
            {
                XDocument doc = XDocument.Load("Data/data.xml");

                return  (from tmpUser in doc.Element("list").Elements("user")
                             select Model.Person.CreatePerson(
                             tmpUser.Element("name").Value,
                             tmpUser.Element("firstname").Value,
                             tmpUser.Element("age").Value)).ToList<Model.Person>();

            }
            catch (Exception ex)
            {
                //traitement exception ...
                Debug.WriteLine(ex.Message);
                return null;
            }
        }
    }
}
